package com.qk.management.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qk.common.PageResult;
import com.qk.entity.Activity;
import com.qk.management.mapper.ActivityMapper;
import com.qk.management.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ActivityServiceImpl extends ServiceImpl<ActivityMapper,Activity> implements ActivityService {
    @Autowired
    private ActivityMapper activitieMapper;


    @Override
    public PageResult<Activity> page(Integer page, Integer pageSize, String channel, Integer type, Integer status) {
        PageHelper.startPage(page,pageSize);
        List<Activity> list=activitieMapper.list(channel,type,status);
        list.forEach((a)->{
            LocalDateTime startTime = a.getStartTime();
            LocalDateTime endTime = a.getEndTime();

        });
        Page<Activity> rs = (Page<Activity>) list;
        return PageResult.<Activity>builder()
                .total(Long.valueOf(rs.getTotal()).intValue())
                .rows(rs.getResult())
                .build();
    }

    @Override
    public void deleteById(Integer id) {
        activitieMapper.deleteById(id);
    }

    @Override
    public void add(Activity activity) {
        activitieMapper.add(activity);
    }

    @Override
    public Activity getById(Integer id) {
        return activitieMapper.getById(id);
    }

    @Override
    public void update(Activity activity) {
        activitieMapper.update(activity);
    }

    @Override
    public List<Activity> findByType(Integer type) {
        return activitieMapper.findByType(type);
    }
}
